package testProject;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.onpositive.page.pagerendering.ShowResourceListRenderer;
import com.onpositive.page.pagerendering.SiteContentRenderer;
import com.onpositive.page.pagerendering.interfaces.ISiteContentRenderer;
import com.onpositive.storage.managers.UnifiedContentProvider;

@SuppressWarnings("serial")
public class ShowContentListServlet extends HttpServlet {
	
	private static ISiteContentRenderer iscr = SiteContentRenderer.getSiteContentRenderer();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		List<String> resources = UnifiedContentProvider.getContentList();
		ShowResourceListRenderer shrlr = new ShowResourceListRenderer();
		
		iscr.initRenderer(getServletContext());
		((SiteContentRenderer)iscr).render(resp, shrlr.getContent(resources), "/reslist.page",false,false);

	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Map par = req.getParameterMap();
		for(Object key : par.keySet()){
			Object val = par.get(key);
			String[] arr = (String[])val;
			for(String res : arr){
				UnifiedContentProvider.deleteContentElement(res);
			}
		}
		//par.clear();
		resp.sendRedirect("reslist.page");
	}
}
